#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
@desc: .

@Project ：kuberCloudTest
@File ：zone.py
@Author ：admin
@Date ：2024/3/20 16:23 
"""
from kuberCloudTest.common.basic import basicUtils
from kuberCloudTest.common.constant import OFFSET, LIMIT, AsyncType
from kuberCloudTest.common.utils import _getOperationType
from kuberCloudTest.urls import Urls


class zoneUtils(basicUtils):

    def __init__(self, accessToken):
        super().__init__(accessToken)


def get_utils(accessToken):
    return zoneUtils(accessToken=accessToken)


def getZone(accessToken, **kwargs):
    """
    获取区域列表
    :param accessToken: access token
    :param kwargs: limit:
                   offset:
                   keyword: xxx
    :return:
    """
    zone_utils = get_utils(accessToken)
    return zone_utils.cloud_http_request.get(Urls.getZone.value,
                                             {
                                                 'offset': kwargs.get('offset', OFFSET),
                                                 'limit': kwargs.get('limit', LIMIT),
                                                 'keyword': kwargs.get('keyword', '')
                                             })


def createZone(accessToken, domainName, **kwargs):
    """
    创建区域
    :param accessToken: access token
    :param domainName: 区域名称
    :param kwargs:  remark: xxx
    :return:
    """
    operationType = 1501
    data = _getOperationType(operationType, AsyncType.SYNC.value)
    data['domainname'] = domainName
    data['remark'] = kwargs.get('remark', '')
    zone_utils = get_utils(accessToken)
    return zone_utils.cloud_http_request.post(Urls.createZone.value, data=data)


def changeZone(accessToken, zoneId):
    """
    切换区域
    :param accessToken: access token
    :param zoneId: 区域uuid
    :return:
    """
    zone_utils = get_utils(accessToken)
    return zone_utils.cloud_http_request.get(Urls.changeZone.value, {'zoneId': zoneId})


def getClusterByZone(accessToken, zoneId, **kwargs):
    """
    获取区域下的集群
    :param accessToken: access token
    :param zoneId: 区域uuid
    :param kwargs: limit:
                   offset:
                   keyword: xxx
    :return:
    """
    zone_utils = get_utils(accessToken)
    return zone_utils.cloud_http_request.get(Urls.getClusterByZone.value,
                                             {
                                                 'domainid': zoneId,
                                                 'offset': kwargs.get('offset', OFFSET),
                                                 'limit': kwargs.get('limit', LIMIT),
                                                 'keyword': kwargs.get('keyword', '')
                                             })


def getMyZone(accessToken):
    """
    获取当前账户所属区域
    :param accessToken:
    :return:
    """
    zone_utils = get_utils(accessToken)
    return zone_utils.cloud_http_request.get(Urls.getMyZone.value)


def startZone(accessToken, zoneIds):
    """
    启用区域
    :param accessToken: access token
    :param zoneIds: 区域uuid (多个使用英文逗号分割)
    :return:
    """
    operationType = 1504
    data = _getOperationType(operationType, AsyncType.SYNC.value)
    data['ids'] = zoneIds
    zone_utils = get_utils(accessToken)
    return zone_utils.cloud_http_request.post(Urls.startZone.value, data=data)


def stopZone(accessToken, zoneIds):
    """
    停用区域
    :param accessToken: access token
    :param zoneIds: 区域uuid (多个使用英文逗号分割)
    :return:
    """
    operationType = 1505
    data = _getOperationType(operationType, AsyncType.SYNC.value)
    data['ids'] = zoneIds
    zone_utils = get_utils(accessToken)
    return zone_utils.cloud_http_request.post(Urls.stopZone.value, data=data)


def deleteZone(accessToken, zoneIds):
    """
    删除区域
    :param accessToken: access token
    :param zoneIds: 区域uuid (多个使用英文逗号分割)
    :return:
    """
    operationType = 1503
    data = _getOperationType(operationType, AsyncType.SYNC.value)
    data['ids'] = zoneIds
    zone_utils = get_utils(accessToken)
    return zone_utils.cloud_http_request.post(Urls.stopZone.value, data=data)

